package com.dq.Controller;


import com.dq.Pojo.Course;
import com.dq.Pojo.Result;
import com.dq.Service.CouService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/course")
public class CourseController {

    @Autowired
    private CouService couService;

    //查询
    @GetMapping
    public Result<PageInfo<Course>> couSearch(@RequestParam Integer  pageNum,
                                              @RequestParam Integer  pageSize,
                                              @RequestParam(required = false) String   courseName,
                                              @RequestParam(required = false) String   startTime){

        PageInfo<Course> courseList = couService.finAll(pageNum,pageSize,courseName,startTime);
        return Result.success(courseList);
    }


    //添加
    @PostMapping
    public  Result<Course> addCou(@RequestBody Course course){
        if(course.getId()==null){
            couService.add(course);
        }else{
            couService.update(course);
        }
        return Result.success();
    }

    //删除
    @DeleteMapping
    public Result del(@RequestParam Integer id){
        System.out.println("id"+id);
        couService.delete(id);
        return Result.success();
    }

    @GetMapping("/find")
    public Result find(){
        List<Course> courseList=couService.find();
        return Result.success(courseList);
    }

    @GetMapping("findByid")
    public Result findByid(@RequestParam Integer id){
        Course course=couService.findByid(id);
        return Result.success(course);
    }
    //学生课程查询
    @GetMapping("/stuCourse")
    public Result stuCourse(@RequestParam Integer id){
        List<Course> courseList=couService.findstu(id);
        return Result.success(courseList);
    }

}
